@extends('public.layouts')
@section('style')
    <meta name="_token" content="{{ csrf_token() }}"/>
    <style>
        .task-th {
            text-align: center;
        }

        .task-td {
            text-align: center;
        }
    </style>
    <link rel="stylesheet" href="{{asset('admin_assets/css/bootstrap-datetimepicker.min.css')}}">
    <link rel="stylesheet" href="{{asset('admin_assets/css/bootstrap.min.css')}}">
    <link rel="stylesheet" href="{{url('admin_assets/css/fileinput.min.css')}}">
    <link rel="stylesheet" href="{{url('admin_assets/css/ip.css')}}">
    <link rel="stylesheet" href="{{url('css/search.css')}}">
@stop
@section('content')
    <div class="content-wrapper" style="background-color: white">
        <section id="list" class="content">
            <div class="row">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                    <div class="box box-info"
                         style="padding-top: 0px;margin-top: 0px;border-top: 0px;border-bottom: solid 1px #0080ff;">
                        <div class="box-body" style="">
                            <div class="row" style="max-height: 50px">
                                <div class="col-lg-2 col-md-2 col-sm-12 col-xs-12" style="margin-top: 1%">
                                    <a href="#" title="返回首页" style="float: left"><i class="fa fa-home fa-2x"
                                                                                    style="width: 100%;color: #009aff">
                                        </i></a>
                                    <a href="{{url('user/work/task')}}"><span
                                                style="font-size: 20px;float: left;color: #009aff">&nbsp;任务管理</span></a>
                                    <div class="clear"></div>
                                </div>
                                <div class="col-lg-4 col-md-6 col-sm-12 col-xs-12 col-lg-offset-6 col-md-offset-4 btn-div">
                                    <button type="button" class="btn btn-info div-btn" data-toggle="modal"
                                            data-target="#modal-addMask"
                                            style="background: #009aff;float: right;margin-left: 1%;margin-top: 1%">新增任务
                                    </button>
                                        {{--<form action="{{url('user/work/taskSearch')}}" method="post"--}}
                                              {{--enctype="multipart/form-data" class="search">--}}
                                            {{--{{csrf_field()}}--}}
                                            {{--<button type="submit" class="fa fa-search fa-lg"></button>--}}
                                            {{--<input type="search" class="search" value="{{$keywords}}" id="search-input"--}}
                                                   {{--name="search">--}}
                                        {{--</form>--}}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            @include('public/alert')
            <div class="row" style="">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                    <div class="table-responsive">
                        <table class="table table-bordered">
                            <thead>
                            <tr>
                                <th class="task-th">任务编号</th>
                                <th class="task-th">申请人</th>
                                <th class="task-th">公司</th>
                                <th class="task-th">任务类别</th>
                                <th class="task-th">类型</th>
                                <th class="task-th">任务发起时间</th>
                                <th class="task-th">任务状态</th>
                                <th class="task-th">任务等级</th>
                                <th class="task-th">执行人</th>
                                <th class="task-th">报件资料</th>
                                <th class="task-th">操作</th>
                            </tr>
                            </thead>
                            <tbody class="list">
                            @if($product->isEmpty())
                                <tr>
                                    <td class="task-td" colspan="11"><h3 align="center">暂无数据</h3></td>
                                </tr>
                            @else
                                @php($i=0)
                                @foreach($product as $k =>$c)
                                    @php($v=$c['Product'])
                                    @if(!empty($c['FirstType']))
                                        <tr>
                                            <td class="task-td" style="vertical-align: middle">{{++$i}}</td>

                                            <td class="task-td applicant"
                                                style="vertical-align: middle">{{$v['applicant']}}</td>
                                            <td class="task-td com"
                                                style="vertical-align: middle">{{$v['company']}}</td>
                                            <td class="task-td is_renew" style="vertical-align: middle">
                                                @if($c['is_renew']==0)
                                                    首次任务
                                                @else
                                                    续费任务
                                                @endif
                                            </td>
                                            <td class="task-td first_type"
                                                style="vertical-align: middle">{{$c['FirstType']['name']}}</td>
                                            <td class="task-td created_at"
                                                style="vertical-align: middle">{{date("Y-m-d",strtotime($v['created_at']))}}</td>
                                            <td class="task-td product_state"
                                                style="vertical-align: middle">{{config('config.product_state')[$c['state']]}}</td>
                                            <td class="task-td product_level"
                                                style="vertical-align: middle">{{config('config.product_level')[$v['level']]}}</td>
                                            <td class="task-td agent" style="vertical-align: middle">
                                                @if(empty($c['agent']))
                                                    暂无
                                                @else
                                                    {{$c['agent']}}
                                                @endif
                                            </td>
                                            <td class="task-td" style="vertical-align: middle">
                                                @if(empty($v['file']))
                                                    未上传
                                                @else
                                                    已上传
                                                @endif
                                            </td>
                                            <td class="task-td " style="vertical-align: middle">
                                                @if($c['is_cancel']==config('config.mission_state_map.cancel'))
                                                    <a href="{{url('user/work/apply',['pid'=>$c['id'],'id'=>$v['id']])}}">重新申请</a>
                                                @else
                                                    @if(empty($v['file']))
                                                        <a href="#" data-toggle="modal" rel="{{$v['id']}}"
                                                           pid="{{$c['id']}}" onclick="setV($(this))"
                                                           data-target="#modal-upload-file">上传资料</a>
                                                    @else
                                                        <a href="{{asset('Uploads/resources/'.$v['file'])}}">查看资料</a>
                                                    @endif
                                                    |  @if($c['first']==0&&$c['tail']==0)
                                                        <a href="{{url('user/work/setFund',['id'=>$c['id']])}}">
                                                            付首款</a>
                                                    @elseif($c['first']==1&&$c['tail']==0)
                                                        <a href="{{url('user/work/setFund',['id'=>$c['id']])}}">
                                                            付尾款
                                                        </a>
                                                    @else
                                                        <span> 已结清</span>
                                                    @endif
                                                @endif
                                            </td>
                                        </tr>
                                    @endif
                                @endforeach
                            @endif
                            </tbody>
                        </table>
                        <div class="">
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </div>
    @include('public.addMaskModal')
    @include('public.upload-fileModal')
@stop
@section('javascript')
    <script src="{{asset('admin_assets/js/fileinput.min.js')}}"></script>
    <script src="{{asset('admin_assets/js/fileinput_locale_zh.js')}}"></script>
    <script src="{{asset('js/ip.js')}}"></script>
    <script src="{{asset('js/list.min.js')}}"></script>

    <script>

        var options = {
            valueNames: ['applicant', 'com','is_renew', 'first_type', 'created_at', 'product_state', 'product_level', 'agent']
        };
        var List = new List('list', options);
        $("#inputFile").fileinput({
            language: 'zh',
            autoReplace: false,
            maxFileCount: 1,
            allowedFileExtensions: ["zip", "7z", "rar"],
            browseClass: "btn btn-primary",
            showUpload: false,
            showCancel: true,
            previewFileIcon: "<i class='glyphicon glyphicon-king'></i>"
        });
        List.search($('#search-input').val());

        function check() {
            return true;
        }

        function setV(e) {
            $('#pp').val(e.attr('pid'));
            $('#i').val(e.attr('rel'));
        }

        function getType(e) {
            $.ajax({
                url: '{{url('user/work/getSecondType')}}',
                type: 'post',
                dataType: 'json',
                data: {
                    'id': e.val()
                },
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                },
                success: function (data) {
                    var type = $('#second_type');
                    type.empty();
                    var size = data.length;
                    if (size <= 0) {
                        type.append('<option value="-1">详细类型</option>');
                    } else {
                        for (var i = 0; i < data.length; i++) {
                            var item = data[i];
                            type.append('<option value="' + item['id'] + '">' + item['name'] + '</option>');
                        }
                    }
                }
            })
        }
    </script>
@stop
